// <copyright file="CavernGenerator.PrivateMethods.cs" company="TenneySoftware">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Robert Tenney</author>
// <email>rob10e@yahoo.com</email>
// <date>April 2009</date>
// <summary>Cavern style level generator module.</summary>

// License:

// Product: RPGRoguelikeEngine .Net
// Author: Robert N. Tenney
// Copyright: April 2009

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation version 2
// of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// This license covers all source code, binaries, and other materials related to this project
// unless specifically stated otherwise.

using System;
using System.Drawing;
using TenneySoftware.Engine;
using TenneySoftware.Engine.Algorithms;

namespace TenneySoftware.LevelGenerator.CavernGenerator {
    /// <content>
    /// This file contains the Private methods for the generator.
    /// </content>
    public partial class Cavern {
        /// <summary>
        /// Sets the name of the current settings in use.
        /// </summary>
        /// <param name="name">Name to set the settings to.</param>
        private void SetName(string name) {
            this.settingName = name;
        }

        /// <summary>
        /// Method to generate the cavern.
        /// </summary>
        /// <returns>True when cavern is generated.</returns>
        private bool GenerateCavern() {
            this.cellAutomata.SkipList.Copy(this.passageOut);
            this.grid = this.cellAutomata.Generate(true);
            this.ConvertToLevel();
            return true;
        }

        /// <summary>
        /// Converts the grid data to TileData type.
        /// </summary>
        private void ConvertToLevel() {
            for (int y = this.level.Bounds.Top; y < this.level.Bounds.Bottom; y++) {
                for (int x = this.level.Bounds.Left; x < this.level.Bounds.Right; x++) {
                    this.level.SetLevel(x, y, new TileData());
                    this.level.GetLevel(x, y).TypeVariation = TileTypeVariation.Cave;
                    if (this.grid[x, y] == GridType.Empty) {
                        this.level.GetLevel(x, y).TypeOfTile = TileType.Floor;
                    }
                }
            }
        }
    }
}